package com.zyh.test;

import com.zyh.domain.PageInfo;
import com.zyh.domain.Student;
import com.zyh.domain.User;
import com.zyh.utils.BaseDAO;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @Author zyh
 * @Date 2024/8/23 14:27
 * @Description
 */

public class BaseDAOTest1 {
    //向表中添加，删除，修改一行数据
    @Test
    public void test1() {
        int count = BaseDAO.changeOneData("insert into student value (null,?,?,?,?,?)", "zyh", 21, 120, "武汉", 2);
        System.out.println("count = " + count);
    }

    // 查询某数据库的一张表的数据
    @Test
    public void test2() {
        String sql = "select * from user where username=? password=?";
        List<User> userList = BaseDAO.selectData("select * from user where username= ? and password= ?", User.class, "zyh", "123");
        if (userList.size() == 1) {
            System.out.println("登陆成功！欢迎" + userList.get(0).getUsername());
        } else {
            System.out.println("登陆失败！");
        }
    }

    @Test
    public void test3() {
        List<Student> list = BaseDAO.selectData("select * from student", Student.class);
        list.forEach(System.out::println);
    }

    // 分页查询
    @Test
    public void test4() {
        PageInfo<Student> studentPageInfo = BaseDAO.selectByPageNum("select * from student", Student.class, 2, 3);
        studentPageInfo.getPageData().forEach(System.out::println);
    }
}
